<?php
require_once('../phplib/include.inc.php');
require_once('../phplib/util/CheckLogin.inc.php');

class Admin_Index extends PageBase{
	public function Ini(){
		$c_id = intval(@$_REQUEST['category']);
		$this->assign('c_id',$c_id);
		$this->GetArticle($c_id);
		$this->GetCategory();
	}
	public function GetCategory(){
		$db = getDb();
		$re = $db->fetch("SELECT * FROM category");
		$this->assign("cats",$re);
	}
	public function GetArticle($c_id){
		$sql = "SELECT a.*,b.cat_name FROM article AS a LEFT JOIN category AS b ON a.c_id=b.c_id ORDER BY a.a_id DESC ";
		if($c_id > 0) $sql = "SELECT a.*,b.cat_name FROM article AS a LEFT JOIN category AS b ON a.c_id=b.c_id WHERE a.c_id=$c_id ORDER BY a.a_id DESC ";
		$db = getDb();
		$re = $db->fetch($sql);
		$this->assign('articles',$re);
	}
}
$a = new Admin_Index("file:".dirname(__FILE__)."/../admin/index.tpl.html");
$a->display();
?>